import java.io.*;
import java.util.Scanner;

//把文件1复制成文件2
public class Demo4 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要复制的文件路径:");
        String s = scanner.next();
        File file = new File(s);

        if(!file.exists()) {
            System.out.println("路径文件不存在!");
            return;
        }

        if(!file.isFile()) {
            System.out.println("文件不是普通文件!");
            return;
        }

        System.out.println("请输入要复制到文件路径:");
        String s1 = scanner.next();
        File file1 = new File(s1);
        if(file1.exists()) {
            System.out.println("要复制的文件已存在!");
            return;
        }

        //复制文件名
        try(InputStream inputStream = new FileInputStream(s)) {
            try(OutputStream outputStream = new FileOutputStream(s1)) {
                byte[] buf = new byte[1024];
                while(true) {
                    int len = inputStream.read(buf);
                    if(len == -1) {
                        break;
                    }
                    outputStream.write(buf,0,len);
                }
            }
        }catch(IOException e) {
            e.printStackTrace();
        }
        System.out.println("复制完成!");
    }
}
